/*
 * 文件名：ConsumableTypeTransactionImpl.java
 * 版权：Copyright by www.wootide.com
 * 描述：
 * 修改人：wuliquan
 * 修改时间：2013-2-25
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */
package com.wootide.cms.service.consumables.consumablesInfo.transaction.impl;

import org.springframework.beans.BeanUtils;

import com.wootide.cms.common.CMSRuntimeException;
import com.wootide.cms.common.ErrorCodes;
import com.wootide.cms.common.Page;
import com.wootide.cms.common.QueryCondition;
import com.wootide.cms.common.QueryResults;
import com.wootide.cms.common.dao.CommonDao;
import com.wootide.cms.log.syslog.RunLog;
import com.wootide.cms.service.consumables.consumablesInfo.dao.ConsumablesTypeInfoDao;
import com.wootide.cms.service.consumables.consumablesInfo.pojo.ConsumablesTypeInfo;
import com.wootide.cms.service.consumables.consumablesInfo.transaction.ConsumablesTypeInfoTransaction;
/**
 * 
 * 易耗品类型类型事务层接口实现
 * 〈功能详细描述〉
 * @author wuliquan
 * @version 2013-2-25
 * @see ConsumablesTypeInfoTransactionImpl
 * @since
 */
public class ConsumablesTypeInfoTransactionImpl implements ConsumablesTypeInfoTransaction
{
    /**
     * 注入运行日志
     */
    private RunLog runLog;
    
    /**
     * 公共数据访问层实例
     */
    private CommonDao commonDao;
    
    /**
     * 易耗品类型类型数据访问层实例
     */
    private ConsumablesTypeInfoDao consumablesTypeInfoDao;
    
    public void addOneConsumableTypeInfo(ConsumablesTypeInfo consumablesTypeInfo)
    {
        // 打印方法入口参数
        runLog.debug("consumablesTypeInfo=" + consumablesTypeInfo);
        // 根据易耗品类型名检查唯一性
        Integer num = consumablesTypeInfoDao.findNumByConsumablesTypeInfoName(consumablesTypeInfo.getConsumablesTypeName());
        //易耗品类型记录已经存在
        if (num > 0)
        {
            throw new CMSRuntimeException("ConsumablesType Existed!",
                    ErrorCodes.Consumables.ConsumablesType.COMSUMABLESTYPE_EXIST);
        }
        commonDao.addOneObject(consumablesTypeInfo);
    }
    
    public ConsumablesTypeInfo delOneConsumableTypeInfo(Integer innerIndex)
    {
        ConsumablesTypeInfo oldConsumableType = consumablesTypeInfoDao.findOneConsumablesTypeInfoByConsumablesTypeId(innerIndex);
        //判断要删除的记录是否存在
        if (null == oldConsumableType)
        {
            throw new CMSRuntimeException(
                    "ConsumableType not Exist!",
                    ErrorCodes.Consumables.ConsumablesType.COMSUMABLESTYPE_NOTEXIST);
        }
        
        commonDao.delOneObject(oldConsumableType);
        //        BeanUtils.copyProperties(oldSupplier, oldSupplierCopy);
        return oldConsumableType;
    }
    
    public ConsumablesTypeInfo modOneConsumableTypeInfo(ConsumablesTypeInfo consumableTypeInfo)
    {
        // 打印方法入口参数
        runLog.debug("consumableTypeInfo=" + consumableTypeInfo);
        ConsumablesTypeInfo oldConsumableType = consumablesTypeInfoDao.findOneConsumablesTypeInfoByConsumablesTypeId(consumableTypeInfo.getConsumablesTypeId());
        
        //判断要修改的记录是否存在
        if (null == oldConsumableType)
        {
            throw new CMSRuntimeException("ConsumableTypeInfo not Exist!",
                    ErrorCodes.Consumables.ConsumablesType.COMSUMABLESTYPE_NOTEXIST);
        }
        
        //获取原始数据副本
        ConsumablesTypeInfo oldConsumableTypeCopy = new ConsumablesTypeInfo();
        BeanUtils.copyProperties(oldConsumableType, oldConsumableTypeCopy);
        
        //修改易耗品类型信息
        oldConsumableType.setConsumablesTypeName(consumableTypeInfo.getConsumablesTypeName());
        oldConsumableType.setConsumablesTypeDesc(consumableTypeInfo.getConsumablesTypeDesc());
        
        return oldConsumableTypeCopy;
    }
    
    public QueryResults queryForPages(Page page, QueryCondition queryConditon)
    {
        // 打印方法入口参数
        runLog.debug("page=" + page);
        runLog.debug("queryConditon=" + queryConditon);
        QueryResults queryResults = commonDao.queryForPages(page, queryConditon);
        return queryResults;
    }
    
    public ConsumablesTypeInfo viewOneConsumableTypeInfo(Integer innerIndex)
    {
        // 打印方法入口参数
        runLog.debug("innerIndex=" + innerIndex);
        ConsumablesTypeInfo consumableTypeInfo = consumablesTypeInfoDao.findOneConsumablesTypeInfoByConsumablesTypeId(innerIndex);
        return consumableTypeInfo;
    }
    
    public void setRunLog(RunLog runLog)
    {
        this.runLog = runLog;
    }
    
    public void setCommonDao(CommonDao commonDao)
    {
        this.commonDao = commonDao;
    }

    public void setConsumablesTypeInfoDao(
            ConsumablesTypeInfoDao consumablesTypeInfoDao)
    {
        this.consumablesTypeInfoDao = consumablesTypeInfoDao;
    }
    
}
